<?php
/**
 * Created by PhpStorm.
 * User: mww
 * Date: 2018/12/17
 * Time: 16:08
 */
namespace app\api\controller;
use think\Db;
class Home extends Base
{
    /**
     * 异地登录验证
     * @return string|void
     */
    public function _initialize()
    {
        extract(input());
        if($user_id != 0){
            $auth = $this->checkAll($user_id,$time,$value,$reqKey);
            if($auth == 112){
                echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
                exit;
            }elseif($auth == 110){
                echo json_encode(['status' => 302, 'msg' => $this->frost]);
                exit;
            }elseif($auth == 1103){
                echo json_encode(['status' => 303, 'msg' => $this->del]);
                exit;
            }
        }

    }
    public function openClose()
    {
        $msg = Db::table('up_about')
            ->where('id',14)
            ->value('content');
        return json(['status'=>200,'msg'=>(int)$msg]);
    }
    public function setopenClose()
    {
        $type = input('type');
        Db::table('up_about')
            ->where('id',14)
            ->setField('content',$type);
        return json(['status'=>200,'msg'=>$type]);
    }
    public function getUserAuth($user_id)
    {
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_auth')
            ->find();
        $userAuth = [];
        if($userInfo['user_auth']){
            $userAuth = explode(',',trim($userInfo['user_auth'],','));
        }
        return $userAuth;
    }
    /**
     * 获取about表数据：
     * type：1 注册协议    2 隐私协议    3 关于我们    4 我的页面的背景图
     * @return string
     */
    public function getAbout()
    {
        extract(input());
        $res = Db::table('up_about')
            ->where('id',$type)
            ->find();
        $phone = '';
        if($type == 5){
            $phone = Db::table('up_about')
                ->where('id',4)
                ->find();
        }
        return json(['status'=>200,'msg'=>$res,'phone'=>$phone]);
    }
    /**
     * location 自动定位返回id：location
     * $location  地区名称
     */
    public function locationGet (){
        extract(input());
        $res = array();
        if(isset($sheng)){
            $shengID = Db::table('up_area')
                ->where('district',$sheng)
                ->where('level',1)
                ->value('district_id');
            $res['sheng'] = $shengID;
        }
        if(isset($shi)){
            $shiID = Db::table('up_area')
                ->where('district',$shi)
                ->where('level',2)
                ->value('district_id');
            $res['shi'] = $shiID;
        }
        if(isset($qu)){
            $quID = Db::table('up_area')
                ->where('district',$qu)
                ->where('level',3)
                ->value('district_id');
            $res['qu'] = $quID;
        }
        return json(['status'=>200,'msg'=>$res]);
    }
    /**
     * 获取首页轮播图
     */
    public function getLunbo(){
        extract(input());
        //1、轮播
        if(!isset($more) || !$more){
            $more = 0;
        }
        $lunbo = Db::table('up_banner')
            ->where('banner_status',1)
            ->where('banner_type',1)
            ->where('banner_where',1)
            ->where('banner_index',1)
            ->where('banner_more',$more)
            ->order('banner_sort desc')
            ->field('banner_id,banner_type,banner_img,banner_title,banner_pp_id,banner_s_id')
            ->select();
        return json(['status'=>200,'msg'=>$lunbo]);
    }
    /**
     * 获取产品页轮播图
     */
    public function getGoodLunbo(){
        extract(input());
        //1、轮播
        if(isset($s_id) && $s_id){
            $where = [
                'pb_pp_id' => $s_id
            ];
        }else{
            $where = [
                'pb_type' => 1,
                'pb_main' => 2,
            ];
        }
        if(!isset($more) || !$more){
            $more = 0;
        }else{
            $more = 1;
        }
        $lunbo = Db::table('up_store_banner')
            ->where($where)
            ->where('pb_more',$more)
            ->order('pb_sort desc')
            ->select();
        return json(['status'=>200,'msg'=>$lunbo]);
    }
    /**
     * 获取首页数据
     * @return \think\response\Json
     */
    public function getHomeData()
    {
        extract(input());
        $where = [
            'pp_status' => 1,
            't_status' => 1,
            'p_status' => 1
        ];
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_d_auth_sids')
            ->find();
        if(!$userInfo['user_d_auth_sids']) return json(['status'=>200,'data'=>[],'pp_nums'=>'共有 0 个品牌']);
        if($userInfo['user_d_auth_sids'] != -1) $where['s_id'] = ['in',$userInfo['user_d_auth_sids']];
        $order1 = 't_sort desc,distance asc';
        $order2 = 'pp_sort desc,distance asc';
        if(isset($keyword) && $keyword){ // 关键字
            $where['pp_name|s_name'] = ['like',"%{$keyword}%"];
        }
        if(isset($t_id) && $t_id){ // 分类
            $where['pp_t_id'] = $t_id;
        }
        if(isset($city) && $city){ // 装饰城
            $where['s_p_id'] = $city;
        }
        if(isset($qu) && $qu){ // 区域
            $where['s_qu'] = $qu;
        }
        if(isset($order) && $order){ // 区域
            if($order == 1){
                $order1 = 'distance asc,t_sort desc';
                $order2 = 'distance asc,pp_sort desc';
            }
            if($order == 2){
                $order1 = 't_sort desc,distance asc';
                $order2 = 'pp_sort desc,distance asc';
            }
            if($order == 3){
                $order1 = 't_click desc,distance asc';
                $order2 = 'pp_click desc,distance asc';
            }
            if($order == 4){
                $order2 = 'pp_letter asc,pp_sort desc';
            }
        }
        //-----------------------pp_id start -----------------------
        $pb_where = [];
        $pb_where2 = [];
        $where_in = '';
        if(isset($menDian) && $menDian){
            $pb_where = [
                'pb_where' => 2
            ];
            if($menDian == 1){
                $where_in = 'in';
            }else{
                $where_in = 'not in';
            }
        }
        if(isset($zhaoPin) && $zhaoPin){
            $pb_where = [
                'pb_where' => 8
            ];
            if($zhaoPin == 1){
                $where_in = 'in';
            }else{
                $where_in = 'not in';
            }
        }
        $special = 1;
        if(isset($menDian) && $menDian && isset($zhaoPin) && $zhaoPin){
            if($menDian == 1 && $zhaoPin == 1){
                $pb_where = [
                    'pb_where' => 2
                ];
                $pb_where2 = [
                    'pb_where' => 8
                ];
                $special = 2;
                $where_in = 'in';
            }
            if($menDian == 2 && $zhaoPin == 2){
                $pb_where = [
                    'pb_where' => ['in','2,8']
                ];
                $where_in = 'not in';
            }
            if($menDian == 1 && $zhaoPin == 2){
                $pb_where = [
                    'pb_where' => 2
                ];
                $pb_where2 = [
                    'pb_where' => 8
                ];
                $where_in = 'in';
            }
            if($menDian == 2 && $zhaoPin == 1){
                $pb_where = [
                    'pb_where' => 8
                ];
                $pb_where2 = [
                    'pb_where' => 2
                ];
                $where_in = 'in';
            }
        }
        if($pb_where){
            $ppinds = Db::table('up_pp_banner')
                ->where($pb_where)
                ->group('pb_pp_id')
                ->column('pb_pp_id');
            if($pb_where2){
                $ppinds2 = Db::table('up_pp_banner')
                    ->where('pb_pp_id','in',$ppinds)
                    ->where($pb_where2)
                    ->group('pb_pp_id')
                    ->column('pb_pp_id');
                if($ppinds2){
                    if($special == 1){
                        $ppinds = array_diff($ppinds,$ppinds2);
                    }else{
                        $ppinds = $ppinds2;
                    }

                }

            }
            $where['s_pp_id'] = [$where_in,$ppinds];
        }
        //----------------------pp_id end --------------------------
        if(isset($more) && $more){
            $user_sps = Db::table('up_u_user')
                ->where('user_id',$user_id)
                ->value('user_sps');
            if($user_sps){
                $where['s_id'] = ['in',$user_sps];
            }else{
                if($more == 1) $where['s_index'] = 2;
                if($more == 2) $where['s_index2'] = 2;
                if($more == 3) $where['s_index3'] = 2;
                if($more == 4) $where['s_index4'] = 2;
                if($more == 5) $where['s_index5'] = 2;
            }

        }
        $subQuery = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($where)
            ->where('s_status',1)
            ->order($order1)
            ->field("t_id,t_sort,t_click,t_letter,t_name,t_thumb,t_remark,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance")
            ->buildSql();
        $data = Db::table($subQuery."a")
            ->group('t_id')
            ->order($order1)
            ->page($page,10)
            ->select();
        $ppnumallOld1 = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($where)
            ->where('s_status',1)
            ->group('pp_id')
            ->count();
        $allSnums = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($where)
            ->where('s_status',1)
            ->count();
        if($data){
            $userYjAuth = 0;
            $userYhAuth = 0;
            if($user_id > 0){
                $userYjAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_yongjin_auth');
                $userYhAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_youhui_auth');
            }
            $field222 = "pp_id,pp_sort,s_pp_id,s_id,s_name,s_two_pic,s_coupon,s_yongjin1,s_yongjin2,s_yongjin3,s_yongjin4,pp_letter,pp_click,pp_name,pp_yongjin1,pp_yongjin2,pp_yongjin3,pp_yongjin4,pp_slogan,pp_two_pic,pp_thumb,pp_coupon,s_star pp_star,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance";
            $field222 .= ',pp_coupon1,pp_coupon2,pp_coupon3,pp_coupon4,s_coupon1,s_coupon2,s_coupon3,s_coupon4';
            foreach ($data as $k => $v){
                $where['pp_t_id'] = $v['t_id'];
//                $subQuery = Db::table('up_store')->alias('s')
//                    ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
//                    ->where($where)
//                    ->order($order2)
//                    ->field("pp_id,pp_sort,s_pp_id,pp_letter,pp_click,pp_name,pp_slogan,pp_two_pic,pp_thumb,pp_coupon,pp_star,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance")
//                    ->buildSql();
//                $son = Db::table($subQuery."a")
//                    ->group('s_pp_id')
//                    ->order($order2)
//                    ->select();
                $son = Db::table('up_store')->alias('s')
                    ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
                    ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
                    ->join('up_place p','s.s_p_id=p.p_id','LEFT')
                    ->where($where)
                    ->where('s_status',1)
                    ->order($order2)
                    ->field($field222)
                    ->select();
                if($son){
                    foreach ($son as $kkk=>$vvv){
                        if($vvv['s_two_pic']){
                            $son[$kkk]['pp_two_pic'] = explode(',',$vvv['s_two_pic']);
                        }else{
                            if($vvv['pp_two_pic']){
                                $son[$kkk]['pp_two_pic'] = explode(',',$vvv['pp_two_pic']);
                            }
                        }
                        //------
                        if($vvv['s_coupon']) $son[$kkk]['pp_coupon'] = $vvv['s_coupon'];
                        if($vvv['s_coupon1']) $son[$kkk]['pp_coupon1'] = $vvv['s_coupon1'];
                        if($vvv['s_coupon2']) $son[$kkk]['pp_coupon2'] = $vvv['s_coupon2'];
                        if($vvv['s_coupon3']) $son[$kkk]['pp_coupon3'] = $vvv['s_coupon3'];
                        if($vvv['s_coupon4']) $son[$kkk]['pp_coupon4'] = $vvv['s_coupon4'];

                        if($vvv['s_yongjin1']) $son[$kkk]['pp_yongjin1'] = $vvv['s_yongjin1'];
                        if($vvv['s_yongjin2']) $son[$kkk]['pp_yongjin2'] = $vvv['s_yongjin2'];
                        if($vvv['s_yongjin3']) $son[$kkk]['pp_yongjin3'] = $vvv['s_yongjin3'];
                        if($vvv['s_yongjin4']) $son[$kkk]['pp_yongjin4'] = $vvv['s_yongjin4'];
                        //------
                        $son[$kkk]['pp_coupon'] = $son[$kkk]['pp_coupon1'];
                        $son[$kkk]['pp_yongjin'] = '';
                        if($userYjAuth > 0){
                            $son[$kkk]['pp_yongjin'] = $vvv['pp_yongjin' . $userYjAuth];
                        }
                        if($userYhAuth > 0){
                            $son[$kkk]['pp_coupon'] = $vvv['pp_coupon' . $userYhAuth];
                        }
                    }
                    $pp_ids = array_column($son, 'pp_id');
                    $pp_ids = array_unique($pp_ids);
                    $data[$k]['son'] = $son;
                    $data[$k]['nums'] = count($pp_ids) . '个品牌·' . count($son) . '个门店';
                }else{
                    unset($data[$k]);
                }

            }
        }
        return json(['status'=>200,'data'=>$data,'pp_nums'=>'共有 ' . $ppnumallOld1 . ' 个品牌·' . $allSnums . ' 个门店']);
    }
    /**
     * 获取开关条件
     * 0主页面设计师显示 1主页面案例显示 2设计师首页视频显示
     * 1显示  2不显示
     */
    public function getOpenClose()
    {
        $user_id = input('user_id');
        $data = Db::table('up_about')
            ->where('id','in','18,21,22')
            ->column('content');
        if($user_id > 0 && $data[0] == 1){
            $can = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_auth_uids');
            if(!$can) $data[0] = 2;
        }
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 获取所有的筛选条件
     */
    public function getAllOptions(){
        extract(input());
        $data = [];
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id value,district text,keykey')
            ->select();
        $places = Db::table('up_place')->where('p_status',1)
            ->order('p_sort desc')
            ->field('p_id value,p_name text,p_key keykey')
            ->select();
        $types = Db::table('up_types')->where('t_status',1)
            ->order('t_sort desc')
            ->field('t_id value,concat(t_name,t_remark) text,t_key keykey')
            ->select();
        $data['分类'] = $types;
        $data['区域'] = $qus;
        $data['商场'] = $places;
        $data['品牌优惠'] = [['value' => 1,'text' => '有优惠','keykey' => 'menDian'],['value' => 2,'text' => '无优惠','keykey' => 'menDian']];
        $data['人才招聘'] = [['value' => 1,'text' => '有招聘','keykey' => 'zhaoPin'],['value' => 2,'text' => '无招聘','keykey' => 'zhaoPin']];
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 获取门店的筛选条件
     */
    public function getGoodsOptions(){
        extract(input());
        $data = [];
        $where = [
            'st_status' => 1
        ];
        if(isset($s_id) && $s_id){
            $ids = Db::table('up_store_goods')
                ->where('good_s_id','like','%,' . $s_id . ',%')
                ->column('good_t_id');
            $where['st_id'] = ['in',$ids];
            $types = Db::table('up_store_types')
                ->where($where)
                ->order('st_sort desc')
                ->field('st_id value,st_name text,concat("t_id") keykey')
                ->select();
        }else{
            $types = Db::table('up_types')
                ->where('t_status',1)
                ->order('t_sort desc')
                ->field('t_id value,t_name text,t_key keykey')
                ->select();
        }
        $where = [
            'spp_status' => 1
        ];
        if(isset($s_id) && $s_id){
            $ids = Db::table('up_store_goods')
                ->where('good_s_id','like','%,' . $s_id . ',%')
                ->column('good_pp_id');
            $where['spp_id'] = ['in',$ids];
            $pps = Db::table('up_store_pps')
                ->where($where)
                ->order('spp_sort desc')
                ->field('spp_id value,spp_name text,concat("pp_id") keykey')
                ->select();
        }else{
//            $pps = Db::table('up_pp')
//                ->where('pp_status',1)
//                ->order('pp_sort desc')
//                ->field('pp_id value,pp_name text,concat("pp_id") keykey')
//                ->select();
            $pps = [];
        }
        $where = [
            'sstyle_status' => 1
        ];
        if(isset($s_id) && $s_id){
            $ids = Db::table('up_store_goods')
                ->where('good_s_id','like','%,' . $s_id . ',%')
                ->column('good_style_id');
            $where['sstyle_id'] = ['in',$ids];
        }
        $syles = Db::table('up_store_style')
            ->where($where)
            ->order('sstyle_sort desc')
            ->field('sstyle_id value,sstyle_name text,concat("style_id") keykey')
            ->select();
        $data['分类'] = $types;
        $data['品牌'] = $pps;
        $data['风格'] = $syles;
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 获取商品或某门店商品
     * 门店商品一定要传s_id
     */
    public function getGoods(){
        extract(input());
        $nullData = Db::table('up_about')
            ->where('id',24)
            ->value('content');
        if($nullData == 2) return json(['status'=>200,'msg'=>[],'good_nums'=>'共计 0 件']);
        $where = [
            'good_status' => 1
        ];
        $order1 = 'good_sort desc';
        if(isset($s_id) && $s_id){
            $where['good_s_id'] = ['like','%,' . $s_id . ',%'];
            if(isset($t_id) && $t_id) $where['good_t_id'] = $t_id;
            if(isset($pp_id) && $pp_id) $where['good_pp_id'] = $pp_id;
            if(isset($keyword) && $keyword) $where['good_name|spp_name|st_name|sstyle_name'] = ['like','%'.$keyword.'%'];
        }else{
            if(isset($t_id) && $t_id) $where['good_s_t_id'] = $t_id;
            if(isset($pp_id) && $pp_id) $where['good_s_pp_id'] = $pp_id;
            if(isset($keyword) && $keyword) $where['good_name|t_name|pp_name'] = ['like','%'.$keyword.'%'];
        }
        if(isset($style_id) && $style_id) $where['good_style_id'] = $style_id;
        //-----
        if(isset($order) && $order){ // 排序
            if($order == 1) $order1 = 'good_sort desc';
            if($order == 2) $order1 = 'good_money_max desc,good_sort desc';
            if($order == 3) $order1 = 'good_money_min asc,good_sort desc';
        }
        if(isset($more) && $more == 1){
            $where['good_index'] = 2;

        }
        $field = 'g.*,pp_name,st_name,spp_name,sstyle_name';
        $datas = Db::table('up_store_goods')->alias('g')
            ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
            ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
            ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
//            ->join('up_store s','g.good_s_id=s.s_id','LEFT')
            ->join('up_pp pp','g.good_s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','g.good_s_t_id=t.t_id','LEFT')
            ->where($where)
            ->field($field)
            ->order($order1)
            ->page($page,20)
            ->select();
        if($datas){
            foreach ($datas as $k => $v){
                $datas[$k]['like'] = 1; //未收藏
                $have = Db::table('up_like_good')
                    ->where('like_user_id',$user_id)
                    ->where('like_good_id',$v['good_id'])
                    ->find();
                if($have) $datas[$k]['like'] = 2; //已收藏
            }
        }
        $datasNums = Db::table('up_store_goods')->alias('g')
            ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
            ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
            ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
//            ->join('up_store s','g.good_s_id=s.s_id','LEFT')
            ->join('up_pp pp','g.good_s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','g.good_s_t_id=t.t_id','LEFT')
            ->where($where)
            ->count();
        return json(['status'=>200,'msg'=>$datas,'good_nums'=>'共计 ' . $datasNums . ' 件']);
    }

    /**
     * 商品参数
     * @return \think\response\Json
     */
    public function goodImages()
    {
        extract(input());
        $where = [
            'pb_pp_id' => $good_id
        ];
        $datas = Db::table('up_good_banner')
            ->where($where)
            ->order('pb_sort desc')
            ->select();
        return json(['status'=>200,'msg'=>$datas]);
    }
    /**
     * 商品详情
     * @return \think\response\Json
     */
    public function goodInfo()
    {
        extract(input());
        $where = [
            'good_id' => $good_id
        ];
        $field = 'g.*,good_s_pp_id,st_name,spp_name,sstyle_name';
        $datas = Db::table('up_store_goods')->alias('g')
            ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
            ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
            ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
//            ->join('up_store s','g.good_s_id=s.s_id','LEFT')
            ->join('up_pp pp','g.good_s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','g.good_s_t_id=t.t_id','LEFT')
            ->where($where)
            ->field($field)
            ->find();
        $datas['like'] = 1; //未收藏
        $have = Db::table('up_like_good')
            ->where('like_user_id',$user_id)
            ->where('like_good_id',$datas['good_id'])
            ->find();
        if($have) $datas['like'] = 2; //已收藏
        //-----------------------------------------------------------
        $can_shu = Db::table('up_good_banner')
            ->where('pb_pp_id',$good_id)
            ->where('pb_where',1)
            ->order('pb_sort desc')
            ->select();
        $shi_jing = Db::table('up_good_banner')
            ->where('pb_pp_id',$good_id)
            ->where('pb_where',2)
            ->order('pb_sort desc')
            ->select();
        $men_dian = [];
        if(isset($lat) && $lat){
            $men_dian = Db::table('up_store')
                ->where('s_id','in',trim($datas['good_s_id'],','))
                ->where('s_status',1)
                ->field("s_id,s_name,s_pp_id,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance")
                ->order('distance asc,s_sort desc')
                ->select();
        }
        //获取门店
        //---------入浏览记录-------
        $today = date('Y-m-d H:i:s');
        $have = Db::table('up_history_goods')
            ->where('h_user_id',$user_id)
            ->where('h_good_id',$good_id)
            ->find();
        if($have){
            Db::table('up_history_goods')->where('h_id',$have['h_id'])->setField('h_time',$today);
        }else{
            Db::table('up_history_goods')->insert([
                'h_good_id' => $good_id,
                'h_user_id' => $user_id,
                'h_time' => $today
            ]);
        }
        //--------------------------------
        return json(['status'=>200,'msg'=>$datas,'can_shu'=>$can_shu,'men_dian'=>$men_dian,'shi_jing'=>$shi_jing]);
    }
    /**
     * 收藏
     * pp_id：品牌id
     *
     */
    public function likeGood(){
        extract(input());
        if($user_id <= 0) return json(['status'=>100,'msg'=>'请登录！']);
        $today = date('Y-m-d H:i:s');
        $like = Db::table('up_like_good')
            ->where('like_user_id',$user_id)
            ->where('like_good_id',$good_id)
            ->find();
        if($like){
            $res = Db::table('up_like_good')->where('like_id',$like['like_id'])->delete();
        }else{
            $res = Db::table('up_like_good')->insert([
                'like_good_id' => $good_id,
                'like_user_id' => $user_id,
                'like_time' => $today
            ]);
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 获取全部南京内的区
     */
    public function getQus(){
        extract(input());
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id,district')
            ->select();
        return json(['status'=>200,'msg'=>$qus]);
    }
    public function getQusCase(){
        extract(input());
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id value,district text')
            ->select();
        return json(['status'=>200,'msg'=>$qus]);
    }
    /**
     * 获取全部装饰城
     */
    public function getPlaces(){
        extract(input());
        $types = Db::table('up_place')->where('p_status',1)
            ->order('p_sort desc')
            ->select();
        return json(['status'=>200,'msg'=>$types]);
    }
    /**
     * 获取全部分类
     */
    public function getTypes(){
        extract(input());
        $types = $this->getAuthTypes();
        return json(['status'=>200,'msg'=>$types]);
    }
    /**
     * 获取全部分类
     */
    public function getAuthTypes($user_id='',$type=''){
        $limit = 500;
        $types = Db::table('up_types')->where('t_status',1)
            ->order('t_sort desc')
            ->page(1,$limit)
            ->select();
        return $types;
        if($type == 1) $limit = 7;
        $userAuth = $this->getUserAuth($user_id);
        if(!$userAuth){
            $types = Db::table('up_types')
                ->order('t_sort desc')
                ->page(1,$limit)
                ->select();
        }else{
            $two = [];
            $ppids = [];
            if(in_array(11,$userAuth)) $two[] = 2;
            if(in_array(12,$userAuth)) $two[] = 8;
            if($two){
                $ppids = Db::table('up_pp_banner')
                    ->where('pb_where','in',$two)
                    ->group('pb_pp_id')
                    ->column('pb_pp_id');
            }
            $str = '';
            foreach ($userAuth as $k => $v){
                if($v <= 10){
                    $str .= 'ten' . $v . '|';
                }
            }
            if($str){
                $str = trim($str,'|');
                if($type == 2){
                    $back_ppids = Db::table('up_pp')
                        ->where('pp_id','in',$ppids)
                        ->whereOr($str,1)
                        ->column('pp_id');
                    return $back_ppids;
                }
                $tids = Db::table('up_pp')
                    ->where('pp_id','in',$ppids)
                    ->whereOr($str,1)
                    ->group('pp_t_id')
                    ->column('pp_t_id');
            }else{
                if($type == 2){
                    return $ppids;
                }
                $tids = Db::table('up_pp')
                    ->where('pp_id','in',$ppids)
                    ->group('pp_t_id')
                    ->column('pp_t_id');
            }
            $types = Db::table('up_types')
                ->where('t_id','in',$tids)
                ->order('t_sort desc')
                ->page(1,$limit)
                ->select();
        }

        return $types;
    }
    /**
     * 搜索
     * keyword：关键字
     */
    public function searchHome(){
        extract(input());
        $where = [
            'pp_status' => 1,
            's_status' => 1,
            'pp_name|s_name' => ['like',"%{$keyword}%"],
        ];
//        $datas = Db::table('up_pp')
//            ->where($where)
//            ->order('pp_name asc')
//            ->page($page,20)
//            ->select();
        $datas = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->where($where)
//            ->group('s_pp_id')
            ->field("pp.*,s_id,s_name")
            ->page($page,20)
            ->select();
        return json(['status'=>200,'msg'=>$datas]);
    }
    /**
     * 获取某分类下的所有品牌
     * t_id：分类名字
     */
    public function getTypePps(){
        extract(input());
        $where = [
            'pp_t_id' => $t_id,
            'pp_status' => 1,
        ];
        $ppids = Db::table('up_store')->alias('s')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where('p_status','<>',1)
            ->group('s_pp_id')
            ->column('s_pp_id');
        if($ppids) $where['pp_id'] = ['not in',$ppids];
        $datas = Db::table('up_pp pp')
            ->where($where)
            ->order('pp_sort desc')
            ->select();
        return json(['status'=>200,'msg'=>$datas]);
    }
    /**
     * 获取某分类下的所有品牌
     * t_id：分类名字
     */
    public function getTypeById(){
        extract(input());
        $where = [
            'pp_t_id' => $t_id,
            'pp_status' => 1,
        ];
//        $ppids = Db::table('up_store')->alias('s')
//            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
//            ->where('p_status','<>',1)
//            ->group('s_pp_id')
//            ->column('s_pp_id');
//        if($ppids) $where['pp_id'] = ['not in',$ppids];
        $datas = Db::table('up_pp pp')
            ->where($where)
            ->order('pp_sort desc')
            ->field('pp_id value,pp_name text,concat("pp_id") keykey')
            ->select();
        return json(['status'=>200,'msg'=>$datas]);
    }

    /**
     * 品牌详情：ppInfo
     * pp_id
     */
    public function ppInfo(){
        extract(input());
        $data = Db::table('up_pp')
            ->where('pp_id',$pp_id)
            ->find();
        //--------------------------------------------------------------
        Db::table('up_pp')->where('pp_id',$pp_id)->setInc('pp_click');
        Db::table('up_types')->where('t_id',$data['pp_t_id'])->setInc('t_click');
        //--------------------------------------------------------------
        if($data['pp_images']){
            $data['pp_images'] = explode(',',$data['pp_images']);
        }
        $userYjAuth = 0;
        $userYhAuth = 0;
        $userPhoneAuth = 1;
        if($user_id > 0){
            $userYjAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_yongjin_auth');
            $userYhAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_youhui_auth');
            $userPhoneAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_phone_auth');
        }
        $like = Db::table('up_like')
            ->where('like_user_id',$user_id)
            ->where('like_pp_id',$pp_id)
            ->find();
        $data['like'] = 1; //我没有赞
        if($like){
            $data['like'] = 2;
        }
        //1、轮播数据
        $lunbo = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',1)
            ->order('pb_sort desc')
            ->select();
        //2、门店数据
        if(isset($s_id) && $s_id){
            $whereS = [
                's_id' => $s_id
            ];
        }else{
            $s_id = 1;
            $whereS = [
                's_pp_id' => $pp_id
            ];
        }
        $store = Db::table('up_store s')
            ->where('s_status',1)
            ->where($whereS)
            ->field("s.*,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance")
            ->order('distance asc')
            ->select();
        $pingmianImg = '';
        if($store){
            $pingmianImg = $store[0]['s_daohang'];
            $aaa = Db::table('up_about')->where('id',6)->value('content');
            $aaa2 = Db::table('up_about')->where('id',4)->value('content');
            foreach ($store as $k => $v){
//                if($userPhoneAuth == 1){
//                    $store[$k]['s_phone'] = $aaa2;
//                }
                if($aaa == 1){
                    $store[$k]['s_phone'] = $aaa2;
                }
                if($v['s_coupon']) $data['pp_coupon'] = $v['s_coupon'];
                if($v['s_coupon1']) $data['pp_coupon1'] = $v['s_coupon1'];
                if($v['s_coupon2']) $data['pp_coupon2'] = $v['s_coupon2'];
                if($v['s_coupon3']) $data['pp_coupon3'] = $v['s_coupon3'];
                if($v['s_coupon4']) $data['pp_coupon4'] = $v['s_coupon4'];

                if($v['s_yongjin1']) $data['pp_yongjin1'] = $v['s_yongjin1'];
                if($v['s_yongjin2']) $data['pp_yongjin2'] = $v['s_yongjin2'];
                if($v['s_yongjin3']) $data['pp_yongjin3'] = $v['s_yongjin3'];
                if($v['s_yongjin4']) $data['pp_yongjin4'] = $v['s_yongjin4'];
            }
            $data['pp_star'] = $store[0]['s_star'];
        }
        $data['pp_yongjin'] = '';
        $data['pp_coupon'] = $data['pp_coupon1'];
        if($userYjAuth > 0){
            $data['pp_yongjin'] = $data['pp_yongjin' . $userYjAuth];
        }
        if($userYhAuth > 0){
            $data['pp_coupon'] = $data['pp_coupon' . $userYhAuth];
        }
        //---------入浏览记录-------
        $today = date('Y-m-d H:i:s');
        $have = Db::table('up_history')
            ->where('h_user_id',$user_id)
            ->where('h_pp_id',$pp_id)
            ->find();
        if($have){
            Db::table('up_history')->where('h_id',$have['h_id'])->setField('h_time',$today);
        }else{
            Db::table('up_history')->insert([
                'h_pp_id' => $pp_id,
                'h_s_id' => $s_id,
                'h_user_id' => $user_id,
                'h_time' => $today
            ]);
        }
        //--------------------------------
        //1、相册（2店面优惠、3品牌介绍、4服务范围、5产品图册、6实景案例、7精英团队、8人才招聘）
        $you_hui = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',2)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $jie_shao = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',3)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $fu_wu = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',4)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $xiang_ce = Db::table('up_store_goods')
            ->where('good_s_id','like','%,' . $s_id . ',%')
            ->where('good_status',1)
//            ->where('pb_info_top',2)
            ->order('good_top desc,good_sort desc')
            ->field('good_thumb pb_url,good_id')
            ->select();
        $an_li = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',6)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $tuan_dui = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',7)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $zhao_pin = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',8)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $yong_jin = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',9)
//            ->where('pb_info_top',2)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        //平面特殊处理
//        $ping_mian = Db::table('up_pp_banner')
//            ->where('pb_pp_id',$pp_id)
//            ->where('pb_where',10)
////            ->where('pb_info_top',2)
//            ->order('pb_info_top desc,pb_sort desc')
//            ->select();
        $ping_mian = [];
        if($pingmianImg){
            $ping_mian = Db::table('up_pp_banner')
                ->where('pb_type',1)
                ->page(1,1)
                ->select();
            $ping_mian[0]['pb_url'] = $pingmianImg;
            $ping_mian[0]['pb_title_up'] = '';
            $ping_mian[0]['pb_title'] = '';
        }

        $shi_pin = Db::table('up_pp_video')
            ->where('v_pp_id',$pp_id)
            ->where('v_s_id',$s_id)
            ->where('v_type',1)
            ->where('v_status',1)
            ->field("concat(v_url,'?vframe/jpg/offset/1') v_thumb,v_url,v_id")
            ->order('v_info_top desc,v_round desc')
            ->select();
//        $allCounts = $this->ppInfoBannerCount($pp_id,$s_id);
        //企业资料
        $zi_liao = Db::table('up_pp_file')
            ->where('pb_pp_id',$pp_id)
            ->order('pb_sort desc')
            ->select();
        //--------------------------------------整套案例-start----------------------------------------------------
        $user_cases = Db::table('up_case_info')->alias('info')
            ->join('up_case c','info.info_case_id=c.case_id','LEFT')
            ->where('info_s_id',$s_id)
            ->where('info_type',1)
            ->where('info_status',1)
            ->where('case_status','in','1,2')
//            ->where('case_done',2)
            ->group('info_case_id')
            ->order('info_top desc,info_sort desc')
            ->column('info_case_id');
        if($user_cases){
            $where = [];
            $where['case_id'] = $user_cases[0];
            if(count($user_cases) > 1) $where['case_id'] = ['in',"{$user_cases[0]},{$user_cases[1]}"];
            $casedata = Db::table('up_case')
                ->where($where)
                ->field("case_two_pic pb_url,case_id")
                ->page(1,2)
                ->select();
            if($casedata){
                foreach ($casedata as $k => $v){
                    if($v['pb_url']){
                        $casedata[$k]['pb_url'] = explode(',',$v['pb_url'])[0];
                    }
                }
            }
        }else{
            $casedata = [];
        }
        //-------------------------------------整套案例--end----------------------------------------------------
        $allCounts = [
            'you_hui' => count($you_hui),
            'jie_shao' => count($jie_shao),
            'fu_wu' => count($fu_wu),
            'xiang_ce' => count($xiang_ce),
            'an_li' => count($an_li),
            'tuan_dui' => count($tuan_dui),
            'zhao_pin' => count($zhao_pin),
            'yong_jin' => count($yong_jin),
            'ping_mian' => count($ping_mian),
            'shi_pin' => count($shi_pin),
            'casedata' => count($user_cases),
        ];
        $data['see_order'] = 1;
        if($user_id > 0) $data['see_order'] = Db::table('up_u_user')->where('user_id',$user_id)->value('user_see_pp');
        return json([
            'status'=>200,'msg'=>$data,'lunbo'=>$lunbo,'store'=>$store,
            'you_hui'=>$you_hui,        //店面优惠 2
            'jie_shao'=>$jie_shao,      //品牌介绍 3
            'fu_wu'=>$fu_wu,            //服务范围 4
            'xiang_ce'=>$xiang_ce,      //产品图册 5
            'an_li'=>$an_li,            //实景案例 6
            'tuan_dui'=>$tuan_dui,      //精英团队 7
            'zhao_pin'=>$zhao_pin,      //人才招聘 8
            'yong_jin'=>$yong_jin,      //佣金    9
            'ping_mian'=>$ping_mian,      //平面  10
            'casedata'=>$casedata,      //整套案例  10

            'zi_liao'=>$zi_liao,      //人才招聘
            'ping_mian_name'=>'商场平面导航',      //人才招聘
            'shi_pin'=>$shi_pin,      //人才招聘
            'allCounts'=>$allCounts,      //人才招聘
        ]);
    }
    public function getppBanner()
    {
        extract(input());
        $data = Db::table('up_pp_banner')
            ->where('pb_pp_id',$pp_id)
            ->where('pb_where',$pb_where)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 收藏
     * pp_id：品牌id
     *
     */
    public function likePp(){
        extract(input());
        if($user_id <= 0) return json(['status'=>100,'msg'=>'请登录！']);
        $today = date('Y-m-d H:i:s');
        $like = Db::table('up_like')
            ->where('like_user_id',$user_id)
            ->where('like_pp_id',$pp_id)
            ->where('like_s_id',$s_id)
            ->find();
        if($like){
            $res = Db::table('up_like')->where('like_id',$like['like_id'])->delete();
        }else{
            $res = Db::table('up_like')->insert([
                'like_pp_id' => $pp_id,
                'like_s_id' => $s_id,
                'like_user_id' => $user_id,
                'like_time' => $today
            ]);
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 获取首页视频
     * @return string
     */
    public function getVideos()
    {
        extract(input());
        $where = [
            'pp_status' => 1,
            'v_type' => 1,
            's_status' => 1,
            'p_status' => 1,
            't_status' => 1,
            'v_status' => 1,
        ];
        if(isset($keyword) && $keyword){
            $where['v_title|pp_name|t_name'] = ['like','%' . $keyword . '%'];
            $data = Db::table('up_pp_video')->alias('v')
                ->join('up_pp pp','v.v_pp_id=pp.pp_id','LEFT')
                ->join('up_store s','v.v_s_id=s.s_id','LEFT')
                ->join('up_place p','s.s_p_id=p.p_id','LEFT')
                ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
                ->where($where)
                ->group('v_pp_id')
//                ->order('v_round desc,v_sort desc,v_time desc')
                ->order('v_top desc,v_sort desc,v_time desc')
                ->field("v_id id,v_url url,v_s_id,v_round,v_title,v_top_title,v_nums,pp_id,pp_name,pp_thumb")
                ->page(1,100)
                ->select();
        }else{
            $data = Db::table('up_pp_video')->alias('v')
                ->join('up_pp pp','v.v_pp_id=pp.pp_id','LEFT')
                ->join('up_store s','v.v_s_id=s.s_id','LEFT')
                ->join('up_place p','s.s_p_id=p.p_id','LEFT')
                ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
                ->where($where)
                ->order('v_top desc,v_round desc,v_sort desc,v_time desc')
                ->field("v_id id,v_url url,v_s_id,v_title,v_top_title,v_round,v_nums,pp_id,pp_name,pp_thumb")
                ->page(1,100)
                ->select();
        }

        foreach ($data as $k => $v){
            $data[$k]['zan'] = 0;
            $have = Db::table('up_zan')
                ->where('zan_v_id',$v['id'])
                ->where('zan_user_id',$user_id)
                ->find();
            if($have) $data[$k]['zan'] = 1;
            $num = rand(1000,10000);
            Db::table('up_pp_video')->where('v_id',$v['id'])->setField('v_round',$num);
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 获取品牌视频
     * @return string
     */
    public function getPpVideos()
    {
        extract(input());
        $where = [
            'v_pp_id' => $pp_id,
            'v_type' => 1,
            's_status' => 1,
            'v_status' => 1,
        ];

        $data = Db::table('up_pp_video')->alias('v')
            ->join('up_pp pp','v.v_pp_id=pp.pp_id','LEFT')
            ->join('up_store s','v.v_s_id=s.s_id','LEFT')
            ->where($where)
            ->order('v_sort desc,v_time desc')
            ->field("v_id id,v_url url,v_s_id,v_title,v_top_title,pp_id,v_nums,pp_name,pp_thumb")
            ->page(1,100)
            ->select();
        foreach ($data as $k => $v){
            $data[$k]['v_thumb'] = $v['url'] . '?vframe/jpg/offset/1';
            $data[$k]['zan'] = 0;
            $have = Db::table('up_zan')
                ->where('zan_v_id',$v['id'])
                ->where('zan_user_id',$user_id)
                ->find();
            if($have) $data[$k]['zan'] = 1;
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 获取设计师视频
     * @return string
     */
    public function getUserVideos()
    {
        extract(input());
        $showuu = Db::name('about')->where('id',22)->value('content');
        if($showuu == 2) return json(['status'=>200,'msg'=>[]]);
        $where = [
            'user_status' => 1,
            'v_status' => 1,
            'v_type' => 2
        ];
        $order = 'v_top desc,v_sort desc,v_time desc';
        if(isset($uid) && $uid) { //设计师视频，不随机，如果是首页随机，else即可
            $where['v_status'] = ['in','1,2'];
            $where['v_pp_id'] = $uid;
        }else{
            $order = 'v_top desc,v_round desc,v_sort desc,v_time desc';
        }
        if(isset($keyword) && $keyword){
//            $where['v_title|user_d_name'] = ['like','%' . $keyword . '%'];
            $where['v_title'] = ['like','%' . $keyword . '%'];
            $data = Db::table('up_pp_video')->alias('v')
                ->join('up_u_user u','v.v_pp_id=u.user_id','LEFT')
                ->where($where)
                ->group('v_pp_id')
                ->order($order)
                ->field("v_id id,v_url url,v_pp_id,v_title,v_top_title,v_round,user_id,v_nums,user_d_name user_username,user_image")
                ->page(1,100)
                ->select();
        }else{
            $data = Db::table('up_pp_video')->alias('v')
                ->join('up_u_user u','v.v_pp_id=u.user_id','LEFT')
                ->where($where)
                ->order($order)
                ->field("v_id id,v_url url,v_pp_id,v_title,v_top_title,v_round,user_id,v_nums,user_d_name user_username,user_image")
                ->page(1,100)
                ->select();
        }

        foreach ($data as $k => $v){
            $data[$k]['v_thumb'] = $v['url'] . '?vframe/jpg/offset/1';
            $data[$k]['zan'] = 0;
            $have = Db::table('up_zan')
                ->where('zan_v_id',$v['id'])
                ->where('zan_user_id',$user_id)
                ->find();
            if($have) $data[$k]['zan'] = 1;
            $num = rand(1000,10000);
            Db::table('up_pp_video')->where('v_id',$v['id'])->setField('v_round',$num);
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 点赞
     * id：视频id
     *
     */
    public function zanVideo(){
        extract(input());
        if($user_id <= 0 || !$user_id){
            return json(['status'=>1024,'msg'=>'请先登录']);
        }
        $today = date('Y-m-d H:i:s');
        $like = Db::table('up_zan')
            ->where('zan_user_id',$user_id)
            ->where('zan_v_id',$id)
            ->find();
        $type = 1;
        if($like){
            $res = Db::table('up_zan')->where('zan_id',$like['zan_id'])->delete();
            Db::table('up_pp_video')->where('v_id',$id)->setDec('v_nums');
            $type = 0;
        }else{
            $res = Db::table('up_zan')->insert([
                'zan_v_id' => $id,
                'zan_user_id' => $user_id,
                'zan_time' => $today
            ]);
            Db::table('up_pp_video')->where('v_id',$id)->setInc('v_nums');
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功','type'=>$type]);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 我有没有点过赞
     * @return string
     */
    public function videoZanMe()
    {
        extract(input());
        $me = 1;
        $have = Db::table('up_zan')
            ->where('zan_v_id',$v_id)
            ->where('zan_user_id',$user_id)
            ->find();
        if($have) $me = 2;
        $v_nums = Db::table('up_pp_video')
            ->where('v_id',$v_id)
            ->value('v_nums');
        return json(['status' => 200,'msg' => $me,'v_nums' => $v_nums]);
    }
    /**
     * 视频评论数据
     * @return string
     */
    public function videoComments()
    {
        extract(input());
        $where = [
            'vc_v_id' => $v_id,
            'vc_status' => 1
        ];
        $data = Db::table('up_video_comment')->alias('vc')
            ->join('up_u_user u','vc.vc_user_id=u.user_id','LEFT')
            ->where($where)
            ->order('vc_time desc')
            ->field("vc.*,user_id,user_username,user_image")
            ->page($page,10)
            ->select();
        if($data){
            foreach ($data as $k => $v){
                $data[$k]['replys'] = Db::table('up_video_comment_reply')->alias('vcr')
                    ->join('up_u_user u','vcr.vcr_user_id=u.user_id','LEFT')
                    ->where('vcr_vc_id',$v['vc_id'])
                    ->where('vcr_status',1)
                    ->order('vcr_time desc')
                    ->field("vcr.*,user_id,user_username,user_image")
                    ->select();
            }
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 直接评论视频
     * @return string
     */
    public function addComment()
    {
        extract(input());
        $data = [
            'vc_v_id' => $v_id,
            'vc_user_id' => $user_id,
            'vc_content' => $vc_content,
            'vc_time' => date('Y-m-d H:i:s'),
        ];
        $res = Db::table('up_video_comment')->insert($data);
        if($res){
            return json(['status' => 200,'msg' => '评论成功']);
        }
        return json(['status' => 100,'msg' => '评论失败，请稍后重试~']);
    }
    /**
     * 评论视频的评论
     * @return string
     */
    public function addReply()
    {
        extract(input());
        $data = [
//            'vcr_v_id' => $v_id,
            'vcr_vc_id' => $vc_id,
//            'vcr_vc_user_id' => $vc_user_id,
            'vcr_user_id' => $user_id,
            'vcr_content' => $vc_content,
            'vcr_time' => date('Y-m-d H:i:s'),
        ];
        $res = Db::table('up_video_comment_reply')->insert($data);
        if($res){
            return json(['status' => 200,'msg' => '评论成功']);
        }
        return json(['status' => 100,'msg' => '评论失败，请稍后重试~']);
    }
    //----------------------------------------------------------------------------
    //-----------------------------------案例-----------------------------------------
    /**
     * 获取案例首页轮播图
     */
    public function caseIndexLunbo(){
        extract(input());
        //1、轮播
        if(isset($case_from) && $case_from >= 1) {
            $lunbo = Db::table('up_banner')
                ->where('banner_status',1)
                ->where('banner_type',1)
                ->where('banner_where',$case_from+3)
                ->where('banner_index',1)
                ->order('banner_sort desc')
                ->field('banner_id,banner_type,banner_img,banner_title,banner_pp_id')
                ->select();
        }else{
            if(!isset($more) || !$more){
                $more = 0;
            }else{
                $more = 6;
            }
            $lunbo = Db::table('up_banner')
                ->where('banner_status',1)
                ->where('banner_type',1)
                ->where('banner_where',2)
                ->where('banner_index',1)
                ->where('banner_more',$more)
                ->order('banner_sort desc')
                ->field('banner_id,banner_type,banner_img,banner_title,banner_pp_id')
                ->select();
        }
        return json(['status'=>200,'msg'=>$lunbo]);
    }
    public function getCaseOptions(){
        extract(input());
        $data = [];
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id value,district text,keykey')
            ->select();
        $rooms = Db::table('up_room')
            ->order('room_sort desc')
            ->field('room_id value,room_name text,room_key keykey')
            ->select();
        $styles = Db::table('up_style')
            ->order('style_sort desc')
            ->field('style_id value,style_name text,style_key keykey')
            ->select();
        $sizes = Db::table('up_size')
            ->order('size_id asc')
            ->field('size_id value,size_name text,size_key keykey')
            ->select();
        $jindu = Db::table('up_jindu')
            ->order('jindu_sort desc')
            ->field('jindu_id value,jindu_name text,jindu_key keykey')
            ->select();
        $data['区域'] = $qus;
        $data['空间'] = $rooms;
        $data['风格'] = $styles;
        $data['面积'] = $sizes;
        $data['进度'] = $jindu;
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 获取用户类型
     */
    public function getUserType(){
        extract(input());
        $user_type = $this->getUserTypeReturn($user_id);
        $sc = Db::table('up_u_user')->where('user_id',$user_id)
            ->field('user_shangchuan,user_d_auth_uids')->find();
        return json(['status'=>200,'msg'=>$user_type,'shang_chuan'=>$sc['user_shangchuan']]);
    }
    /**
     * 获取用户类型
     */
    public function getUserTypeReturn($user_id,$hhh=1){
        extract(input());
        $user_type = 1;
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_type')
            ->find();
        if($userInfo){
            $user_types = explode(',',$userInfo['user_type']);
            if(in_array(3,$user_types)){
                $user_type = 3; //推荐
                if(in_array(2,$user_types) || in_array(4,$user_types)){
                    $user_type = 4;
                }
            }else{
                if(in_array(2,$user_types) || in_array(4,$user_types)){
                    $user_type = 2;
                }
            }

//            if($hhh == 2){
//                if(in_array(3,$user_types)){
//                    $user_type = 3;
//                }
//                if(in_array(2,$user_types) || in_array(4,$user_types)){
//                    $user_type = 2;
//                }
//            }
        }
        return $user_type;
    }
    /**
     * 获取案例首页数据
     * @return \think\response\Json
     */
    public function getCaseHomeData()
    {
        extract(input());
        $showuu = Db::name('about')->where('id',21)->value('content');
        if($showuu == 2) return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
        $where = [
            'case_status' => 1
        ];
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_type,user_my,user_see_cases,user_case_jindus')
            ->find();
        //能看到的案例和类型
        if(!$userInfo['user_see_cases'] || !$userInfo['user_case_jindus']) return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
        if($userInfo['user_see_cases'] != -1) $where['case_id'] = ['in',$userInfo['user_see_cases']];
        if($userInfo['user_case_jindus'] != -1) $where['case_jindu'] = ['in',$userInfo['user_case_jindus']];
//        我的页面进来
//        if($userInfo['user_my'] == 1) $where['case_done'] = 2;
        $where['case_jianqie'] = 2;
        if(isset($case_from) && $case_from >= 1) {
//            $user_type = $this->getUserTypeReturn($user_id,2);
            if(isset($where['case_done'])) unset($where['case_done']);
            if($case_from == 1){
                $where['case_jianqie'] = 1;
            }
            if($case_from == 2){
                $where['case_jianqie'] = 1;
                $where['case_excel_uids'] = ['like',"%,$user_id,%"];
            }
        }
        if(isset($uid) && $uid) { //只要传uid就行
//            $where['case_uids'] = ['like',"%,$uid,%"];
//            $where_2['case_uids'] = ['like',"%,$uid,%"];
            $user_cases = Db::table('up_case_info')
                ->where('info_type',2)
                ->where('info_user_id',$uid)
                ->where('info_status',1)
                ->group('info_case_id')
                ->column('info_case_id');
            if($user_cases){
                $where['case_id'] = ['in',$user_cases];
            }else{
                return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
            }
            $where['case_status'] = ['in','1,2'];
        }
        if(isset($keyword) && $keyword){ // 空间
            $where['case_name'] = ['like','%'.$keyword.'%'];
        }
        $order1 = 'case_sort desc';
        if(isset($room_id) && $room_id){ // 空间
            $where['case_room'] = $room_id;
        }
        if(isset($qu) && $qu){ // 区域
            $where['case_qu'] = $qu;
        }
        if(isset($style_id) && $style_id){ // 风格
            $where['case_style'] = $style_id;
        }
        if(isset($size_id) && $size_id){ // 面积
            $sizeData = Db::table('up_size')->where('size_id',$size_id)->find();
            $where['case_size'] = ['between',"{$sizeData['size_min']},{$sizeData['size_max']}"];
        }
        $bianids = Db::table('up_case_bianhua')->where('cb_uid',$user_id)->column('cb_caseid');
        if(isset($order) && $order){ // 区域
            if($order == 1){
                $order1 = 'case_time desc,case_sort desc';
            }
            if($order == 2){
                $order1 = 'case_letter asc,case_sort desc';
            }
            if($order == 3){
                $order1 = 'case_size desc,case_sort desc';
            }
            if($order == 4){
                $order1 = 'case_size asc,case_sort desc';
            }
            if($order == 5){
                $order1 = 'distance asc,case_sort desc';
            }
            //设计师排序和公司排序，有设计师和无设计师
            if($order == 6){
                $order1 = 'case_shejishi_letter asc,case_sort desc';
            }
            if($order == 7){
                $order1 = 'case_company_letter asc,case_sort desc';
            }
            if($order == 8){
                $where['case_shejishi_have'] = 1;
            }
            if($order == 9){
                if($bianids) $where['case_id'] = ['not in',$bianids];
                //$where['case_bianhua'] = 2;
				$order1 = 'case_bianhua desc,case_sort desc';
            }
        }
//        if(isset($shaixuan) && $shaixuan){ // 筛选
//            if($shaixuan == 1){
//                $where['case_shejishi_have'] = 2;
//            }
//            if($shaixuan == 2){
//                $where['case_shejishi_have'] = 1;
//            }
//            if($shaixuan == 3){
//                $where['case_bianhua'] = 2;
//            }
//        }
        if(isset($more) && $more == 1){
            $user_cases = Db::table('up_u_user')
                ->where('user_id',$user_id)
                ->value('user_cases');
            if($user_cases){
                $where['case_id'] = ['in',$user_cases];
            }else{
                $where['case_index'] = 2;
            }

        }
        if(isset($s_id) && $s_id > 0){
            $user_cases = Db::table('up_case_info')
                ->where('info_s_id',$s_id)
                ->where('info_status',1)
                ->group('info_case_id')
                ->column('info_case_id');
            if($user_cases){
                $where['case_id'] = ['in',$user_cases];
            }else{
                return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
            }
            $where['case_status'] = ['in','1,2'];
        }
        //-----------------------pp_id start -----------------------
        $where_2 = $where;
//        if(isset($case_from) && $case_from == 1) {
//            $where['case_see_uids'] = -1;
//            $where_2['case_see_uids'] = ['like','%,' . $user_id . ',%'];
//        }
        if(isset($jindu) && $jindu) {
            $where['case_jindu'] = $jindu;
            $where_2['case_jindu'] = $jindu;
        }
        $data = Db::table('up_case')->alias('c')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
            ->where($where)
//            ->where(function ($query) use ($where) {
//                $query->where($where);
//            })
//            ->whereOr(function ($query) use ($where_2) {
//                $query->where($where_2);
//            })
            ->order($order1)
            ->field("c.*,jindu_name,room_name,style_name,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - case_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(case_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - case_lon * PI() / 180) / 2),2))) * 1000) AS distance")
            ->page($page,10)
            ->select();
        if($data){
            foreach ($data as $k => $v){
                if($bianids && $v['case_bianhua'] == 2){
                    if(in_array($v['case_id'],$bianids)) $data[$k]['case_bianhua'] = 1;
                }
                if($v['case_two_pic']){
                    $data[$k]['case_two_pic'] = explode(',',$v['case_two_pic']);
                }
            }
        }
        //------------------------数量--------------------------------------------------------
        $nums = Db::table('up_case')->alias('c')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
            ->where($where)
//            ->where(function ($query) use ($where) {
//                $query->where($where);
//            })
//            ->whereOr(function ($query) use ($where_2) {
//                $query->where($where_2);
//            })
            ->count();
        return json(['status'=>200,'data'=>$data,'case_nums'=>'共有' . $nums . '个']);
    }
    /**
     * 获取案例详情
     * @return \think\response\Json
     */
    public function getCaseInfo()
    {
        extract(input());
        $where = [
            'case_id' => $case_id
        ];
        $field = 'c.*,room_name,jindu_name,style_name,district';
        $field .= ",ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - case_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(case_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - case_lon * PI() / 180) / 2),2))) * 1000) AS distance";
        $data = Db::table('up_case')->alias('c')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->join('up_area a','c.case_qu=a.district_id','LEFT')
            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
            ->where($where)
            ->field($field)
            ->find();
        $like = Db::table('up_like_case')
            ->where('like_user_id',$user_id)
            ->where('like_case_id',$case_id)
            ->find();
        $data['like'] = 1; //我没有收藏
        if($like){
            $data['like'] = 2;
        }
//        if($data['case_banner']) $data['case_banner'] = explode(',',$data['case_banner']);
//        if($data['case_video']) $data['case_video'] = explode(',',$data['case_video']);
//        if($data['case_imgs']) $data['case_imgs'] = explode(',',$data['case_imgs']);
//        if($data['case_photo']) $data['case_photo'] = explode(',',$data['case_photo']);
        //1、相册（2店面优惠、3品牌介绍、4服务范围、5产品图册、6实景案例、7精英团队、8人才招聘）
        $data['case_banner'] = Db::table('up_case_banner')
            ->where('pb_pp_id',$case_id)
            ->where('pb_where',1)
            ->order('pb_sort desc')
            ->column('pb_url');
        $data['case_imgs'] = Db::table('up_case_banner')
            ->where('pb_pp_id',$case_id)
            ->where('pb_where',2)
            ->order('pb_sort desc')
            ->select();
        $data['case_photo'] = Db::table('up_case_banner')
            ->where('pb_pp_id',$case_id)
            ->where('pb_where',3)
            ->order('pb_sort desc')
            ->select();
        $data['case_video'] = Db::table('up_case_banner')
            ->where('pb_pp_id',$case_id)
            ->where('pb_where',4)
            ->order('pb_sort desc')
            ->select();
        $stores = Db::table('up_case_info')->alias('info')
            ->join('up_store s','info.info_s_id=s.s_id','LEFT')
            ->join('up_pp pp','info.info_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','info.info_t_id=t.t_id','LEFT')
            ->join('up_u_user u','info.info_user_id=u.user_id','LEFT')
            ->where('info_case_id',$case_id)
            ->where('info_status',1)
            ->order('info_sort desc,info_time asc')
            ->field("info.*,t_name,s_name,pp_name,user_d_company,user_d_name,user_d_company_address")
            ->select();
        if($stores){
            foreach ($stores as $k => $v){

                if($v['info_type'] == 2){
                    $juliData = Db::table('up_u_user')
                        ->where('user_id',$v['info_user_id'])
                        ->field("ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - user_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(user_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - user_lon * PI() / 180) / 2),2))) * 1000) AS distance")
                        ->find();
                    $stores[$k]['info_designer'] = '设计师：' . $v['user_d_name'];
                }else{
                    $juliData = Db::table('up_store')
                        ->where('s_id',$v['info_s_id'])
                        ->field("ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - s_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - s_lon * PI() / 180) / 2),2))) * 1000) AS distance")
                        ->find();
                }
                $stores[$k]['distance'] = $juliData['distance'];//距离
                $stores[$k]['info_img'] = Db::table('up_case_info_banner')
                    ->where('pb_pp_id',$v['info_id'])
                    ->order('pb_sort desc')
                    ->select();
            }
        }
        $user_type = 1;
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_type')
            ->find();
        if($userInfo){
            $user_types = explode(',',$userInfo['user_type']);
            if(in_array(2,$user_types)){
                $user_type = 2;
            }
            if(in_array(3,$user_types)){
                $user_type = 3;
                $caseuid = trim($data['case_excel_uids'],',');
                $caseuid = explode(',',$caseuid);
                if($user_id <= 0 || !in_array($user_id,$caseuid)) {
                    $user_type = 1;
                    if(in_array(2,$user_types)){
                        $user_type = 2;
                    }
                }
            }
            if(in_array(4,$user_types)) $user_type = 3;
        }
        if(isset($nono) && $nono == 1) { //从主页或设计师进来的详情
            $user_type = 1;
        }
        //---------入浏览记录-------
        if($user_id > 0){
            $today = date('Y-m-d H:i:s');
            $have = Db::table('up_history_case')
                ->where('h_user_id',$user_id)
                ->where('h_case_id',$case_id)
                ->find();
            if($have){
                Db::table('up_history_case')->where('h_id',$have['h_id'])->setField('h_time',$today);
            }else{
                Db::table('up_history_case')->insert([
                    'h_case_id' => $case_id,
                    'h_user_id' => $user_id,
                    'h_time' => $today
                ]);
            }
            if($data['case_bianhua'] == 2){
                $have = Db::table('up_case_bianhua')
                    ->where('cb_uid',$user_id)
                    ->where('cb_caseid',$case_id)
                    ->find();
                if($have){
                    $data['case_bianhua'] = 1;
                }else{
                    Db::table('up_case_bianhua')->insert([
                        'cb_caseid' => $case_id,
                        'cb_uid' => $user_id
                    ]);
                }
            }
        }

        //--------------------------------
        return json(['status'=>200,'data'=>$data,'stores'=>$stores,'user_type'=>$user_type]);
    }
    /**
     * 收藏
     * pp_id：品牌id
     *
     */
    public function likeCase(){
        extract(input());
        if($user_id <= 0) return json(['status'=>100,'msg'=>'请登录！']);
        $today = date('Y-m-d H:i:s');
        $like = Db::table('up_like_case')
            ->where('like_user_id',$user_id)
            ->where('like_case_id',$case_id)
            ->find();
        if($like){
            $res = Db::table('up_like_case')->where('like_id',$like['like_id'])->delete();
        }else{
            $res = Db::table('up_like_case')->insert([
                'like_case_id' => $case_id,
                'like_user_id' => $user_id,
                'like_time' => $today
            ]);
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 获取某门店或设计师的订单汇总
     * @return \think\response\Json
     */
    public function getStoreCases()
    {
        extract(input());
        if(isset($uid) && $uid){
            $where = [
                'info_type' => 2,
                'info_user_id' => $uid
            ];
        }else{
            $where = [
                'info_s_id' => $s_id
            ];
        }

        $field = 'info.*,c.*,room_name,style_name';
        $field .= ",ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - case_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(case_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - case_lon * PI() / 180) / 2),2))) * 1000) AS distance";
        $data = Db::table('up_case_info')->alias('info')
            ->join('up_case c','info.info_case_id=c.case_id','LEFT')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->where($where)
            ->where('info_status',1)
            ->order('case_time desc')
            ->field($field)
            ->select();
        $money = 0;
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_type')
            ->find();
        if($data){
            foreach ($data as $k => $v){
                $user_type = 1;
//                if($v['case_banner']) $data[$k]['case_banner'] = explode(',',$v['case_banner']);
//                if($v['case_video']) $data[$k]['case_video'] = explode(',',$v['case_video']);
//                if($v['case_imgs']) $data[$k]['case_imgs'] = explode(',',$v['case_imgs']);
//                if($v['case_photo']) $data[$k]['case_photo'] = explode(',',$v['case_photo']);
                $data[$k]['case_photo'] = Db::table('up_case_info_banner') //还叫case_photo
                    ->where('pb_pp_id',$v['info_id'])
                    ->order('pb_sort desc')
                    ->select();
                $money += $v['info_money'];
                if($userInfo){
                    $user_types = explode(',',$userInfo['user_type']);
                    if(in_array(4,$user_types)) {
                        $user_type = 3;
                    }else{
                        if(in_array(2,$user_types)){
                            $user_type = 2;
                        }
                        if(in_array(3,$user_types)){
                            $caseuid = trim($v['case_excel_uids'],',');
                            $caseuid = explode(',',$caseuid);
                            if($user_id <= 0 || !in_array($user_id,$caseuid)) {
                                $user_type = 1;
                                if(in_array(2,$user_types)){
                                    $user_type = 2;
                                }
                            }
                        }
                    }
                }
                $data[$k]['user_type'] = $user_type;
                if($user_type == 1 || $user_type == 2){
                    $money -= $v['info_money'];
                }
            }
        }
        if($money <= 0) $money = -1;
        return json(['status'=>200,'data'=>$data,'money'=>$money]);
    }
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    //------------------------------------- 设计师相关接口 ---------------------------------------------------------
    /**
     * 获取设计师轮播图
     */
    public function userIndexLunbo(){
        extract(input());
        //1、轮播
        if(!isset($more) || !$more){
            $more = 0;
        }else{
            $more = 7;
        }
        $lunbo = Db::table('up_banner')
            ->where('banner_status',1)
            ->where('banner_type',1)
            ->where('banner_where',3)
            ->where('banner_index',1)
            ->where('banner_more',$more)
            ->order('banner_sort desc')
            ->field('banner_id,banner_type,banner_img,banner_title,banner_pp_id')
            ->select();
        return json(['status'=>200,'msg'=>$lunbo]);
    }
    /**
     * 获取设计师数据选项
     */
    public function getUserOptions(){
        extract(input());
        $data = [];
        $rooms = Db::table('up_room_copy')
            ->order('room_sort desc')
            ->field('room_id value,room_name text,room_key keykey')
            ->select();
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id value,district text,keykey')
            ->select();
        $sizes = Db::table('up_size_copy')
            ->order('size_id asc')
            ->field('size_id value,size_name text,size_key keykey')
            ->select();
        $zhiwu = Db::table('up_zhiwu')
            ->order('zhiwu_sort desc')
            ->field('zhiwu_id value,zhiwu_name text,zhiwu_key keykey')
            ->select();
        $styles = Db::table('up_style')
            ->order('style_sort desc')
            ->field('style_id value,style_name text,style_key keykey')
            ->select();
        $years = Db::table('up_year')
            ->order('year_id asc')
            ->field('year_id value,year_name text,year_key keykey')
            ->select();
        $data['分类'] = $rooms;
        $data['区域'] = $qus;
        $data['收费'] = $sizes;
        $data['职务'] = $zhiwu;
        $data['风格'] = $styles;
        $data['工作年限'] = $years;
        return json(['status'=>200,'msg'=>$data]);
    }

    /**
     * 获取设计师数据
     * @return \think\response\Json
     */
    public function getUserHomeData()
    {
        extract(input());
        $showuu = Db::name('about')->where('id',18)->value('content');
        if($showuu == 2) return json(['status'=>200,'data'=>[],'case_nums'=>'共有0位设计师']);
        $where = [
            'user_status' => 1,
            'user_d_type' => 2,
        ];
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_d_auth_uids')
            ->find();
        if($userInfo['user_d_auth_uids'] != -1) $where['user_id'] = ['in',$userInfo['user_d_auth_uids']];
        $order1 = 'user_sort desc';
        if(isset($keyword) && $keyword){ // 空间
            $where['user_d_name|user_d_company'] = ['like','%'.$keyword.'%'];
        }
        if(isset($room_id) && $room_id){ // 空间
            $where['user_d_room'] = ['like','%'.$room_id.'%'];
        }
        if(isset($qu) && $qu){ // 区域
            $where['user_d_qu'] = $qu;
        }
        if(isset($style_id) && $style_id){ // 风格
            $where['user_d_style'] = ['like','%,' . $style_id . ',%'];
        }
        if(isset($zhaopin) && $zhaopin){ // 招聘 0不限 1没有 2有
            $where['user_d_zhaopin'] = $zhaopin;
        }
        if(isset($zhiwu_id) && $zhiwu_id){ // 招聘 0不限 1没有 2有
            $where['user_d_zhiwu'] = $zhiwu_id;
        }
        if(isset($sex) && $sex){ // 招聘 0不限 1没有 2有
            $where['user_d_sex'] = $sex;
        }
        if(isset($year_id) && $year_id){ // 招聘 0不限 1没有 2有
            $sizeData = Db::table('up_year')->where('year_id',$year_id)->find();
            $where['user_d_year'] = ['between',"{$sizeData['year_min']},{$sizeData['year_max']}"];
        }
        if(isset($size_id) && $size_id){ // 面积
            $sizeData = Db::table('up_size_copy')->where('size_id',$size_id)->find();
            $where['user_d_money_min|user_d_money_max'] = ['between',"{$sizeData['size_min']},{$sizeData['size_max']}"];
        }
        if(isset($order) && $order){ // 区域
            if($order == 2){
                $order1 = 'user_letter asc,user_sort desc';
            }
            if($order == 3){
                $order1 = 'distance asc,user_sort desc';
            }
            if($order == 4){
                $order1 = 'user_d_money_max desc,user_d_money_min desc,user_sort desc';
            }
            if($order == 5){
                $order1 = 'user_d_money_min asc,user_d_money_max asc,user_sort desc';
            }
            if($order == 6){
                $order1 = 'user_letter_com asc,user_sort desc';
            }
            if($order == 7){
                $order1 = 'user_order_time desc,user_sort desc';
            }
        }
        if(isset($more) && $more == 1){
            $user_users = Db::table('up_u_user')
                ->where('user_id',$user_id)
                ->value('user_users');
            if($user_users){
                $where['user_id'] = ['in',$user_users];
            }else{
                $where['user_d_index'] = 2;
            }

        }
        //-----------------------pp_id start -----------------------
        $data = Db::table('up_u_user')->alias('c')
            ->join('up_zhiwu z','c.user_d_zhiwu=z.zhiwu_id','LEFT')
//            ->join('up_room_copy r','c.user_d_room=r.room_id','LEFT')
            ->join('up_style s','c.user_d_style=s.style_id','LEFT')
            ->where($where)
            ->order($order1)
            ->field("c.*,style_name,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - user_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(user_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - user_lon * PI() / 180) / 2),2))) * 1000) AS distance")
            ->page($page,10)
            ->select();
        if($data){
            $userYjAuth = 1;
            $userYhAuth = 1;
            if($user_id > 0){
                $userYjAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_yongjin_auth');
                $userYhAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_youhui_auth');
            }
            foreach ($data as $k => $v){
                if($v['user_d_two_pic']){
                    $data[$k]['user_d_two_pic'] = explode(',',$v['user_d_two_pic']);
                }
                if($userYhAuth > 1) $data[$k]['user_d_youhui'] = $v['user_d_youhui' . $userYhAuth];
                if($userYjAuth > 1) $data[$k]['user_d_yongjin'] = $v['user_d_yongjin' . $userYjAuth];
            }
        }
        //------------------------数量--------------------------------------------------------
        $nums = Db::table('up_u_user')->alias('c')
            ->join('up_zhiwu z','c.user_d_zhiwu=z.zhiwu_id','LEFT')
//            ->join('up_room_copy r','c.user_d_room=r.room_id','LEFT')
            ->join('up_style s','c.user_d_style=s.style_id','LEFT')
            ->where($where)
            ->count();
        return json(['status'=>200,'data'=>$data,'case_nums'=>'共有' . $nums . '位设计师']);
    }
    /**
     * 获取设计师详情
     * @return \think\response\Json
     */
    public function getCaseUserInfo()
    {
        extract(input());
        $where = [
            'user_id' => $uid
        ];
        $field = 'c.*';
        $field .= ",ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - user_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(user_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - user_lon * PI() / 180) / 2),2))) * 1000) AS distance";
        $data = Db::table('up_u_user')->alias('c')
            ->where($where)
            ->field($field)
            ->find();
        $userPhoAuth = 1;
        $userYjAuth = 1;
        $userYhAuth = 1;
        if($user_id && $user_id > 0){
            $userPhoAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_phone_auth');
            $userYjAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_yongjin_auth');
            $userYhAuth = Db::table('up_u_user')->where('user_id',$user_id)->value('user_d_youhui_auth');
        }
        if($userPhoAuth == 1){
            $aaa2 = Db::table('up_about')->where('id',4)->value('content');
            $data['user_phone'] = $aaa2;
        }
        if($userYhAuth > 1){
            $data['user_d_youhui'] = $data['user_d_youhui' . $userYhAuth];
        }
        if($userYjAuth > 1){
            $data['user_d_yongjin'] = $data['user_d_yongjin' . $userYjAuth];
        }
        $like = Db::table('up_like_user')
            ->where('like_user_id',$user_id)
            ->where('like_other_id',$uid)
            ->find();
        $data['like'] = 1; //我没有收藏
        if($like){
            $data['like'] = 2;
        }
        //1、相册（2店面优惠、3品牌介绍、4服务范围、5产品图册、6实景案例、7精英团队、8人才招聘）
        $lun_bo = Db::table('up_user_banner')
            ->where('pb_pp_id',$uid)
            ->where('pb_where',1)
            ->order('pb_sort desc')
            ->select();
        $you_hui = Db::table('up_user_banner')
            ->where('pb_pp_id',$uid)
            ->where('pb_where',2)
            ->order('pb_sort desc')
            ->select();
        $yong_jin = Db::table('up_user_banner')
            ->where('pb_pp_id',$uid)
            ->where('pb_where',3)
            ->order('pb_sort desc')
            ->select();
        $tuan_dui = Db::table('up_user_banner')
            ->where('pb_pp_id',$uid)
            ->where('pb_where',4)
            ->order('pb_info_top desc,pb_sort desc')
            ->select();
        $zhao_pin = Db::table('up_user_banner')
            ->where('pb_pp_id',$uid)
            ->where('pb_where',5)
            ->order('pb_sort desc')
            ->select();
        $shi_pin = Db::table('up_pp_video')
            ->where('v_pp_id',$uid)
            ->where('v_type',2)
            ->where('v_status','in','1,2')
            ->field("concat(v_url,'?vframe/jpg/offset/1') v_thumb,v_url,v_id")
            ->order('v_info_top desc,v_round desc')
            ->select();
        //--------------------------------------整套案例-start----------------------------------------------------
        $user_cases = Db::table('up_case_info')->alias('info')
            ->join('up_case c','info.info_case_id=c.case_id','LEFT')
            ->where('info_type',2)
            ->where('info_user_id',$uid)
            ->where('info_status',1)
            ->where('case_status','in','1,2')
//            ->where('case_done',2)
            ->group('info_case_id')
            ->order('info_top desc,info_sort desc')
            ->column('info_case_id');
        if($user_cases){
            $where = [];
            $where['case_id'] = $user_cases[0];
            if(count($user_cases) > 1) $where['case_id'] = ['in',"{$user_cases[0]},{$user_cases[1]}"];
            $casedata = Db::table('up_case')
                ->where($where)
                ->field("case_two_pic pb_url")
                ->page(1,2)
                ->select();
            if($casedata){
                foreach ($casedata as $k => $v){
                    if($v['pb_url']){
                        $casedata[$k]['pb_url'] = explode(',',$v['pb_url'])[0];
                    }
                }
            }
        }else{
            $casedata = [];
        }
        //-------------------------------------整套案例--end----------------------------------------------------
        $allCounts = [
            'tuan_dui' => count($tuan_dui),
            'shi_pin' => count($shi_pin),
            'casedata' => count($user_cases)
        ];
        //---------入浏览记录-------
        if($user_id > 0){
            $today = date('Y-m-d H:i:s');
            $have = Db::table('up_history_user')
                ->where('h_user_id',$user_id)
                ->where('h_other_id',$uid)
                ->find();
            if($have){
                Db::table('up_history_user')->where('h_id',$have['h_id'])->setField('h_time',$today);
            }else{
                Db::table('up_history_user')->insert([
                    'h_other_id' => $uid,
                    'h_user_id' => $user_id,
                    'h_time' => $today
                ]);
            }
        }
        $data['see_order'] = 1;
        if($user_id > 0) $data['see_order'] = Db::table('up_u_user')->where('user_id',$user_id)->value('user_see_user');
        //--------------------------------
        return json([
            'status'=>200,
            'msg'=>$data,          //设计师详情
            'lun_bo'=>$lun_bo,     //轮播图
            'you_hui'=>$you_hui,   //优惠图
            'yong_jin'=>$yong_jin, //佣金图
            'tuan_dui'=>$tuan_dui, //团队图
            'zhao_pin'=>$zhao_pin, //招聘图
            'shi_pin'=>$shi_pin, //视频
            'casedata'=>$casedata, //设计师案例
            'allCounts'=>$allCounts, //
        ]);
    }
    /**
     * 收藏设计师
     * uid
     *
     */
    public function likeCaseUser(){
        extract(input());
        if($user_id <= 0) return json(['status'=>100,'msg'=>'请登录！']);
        $today = date('Y-m-d H:i:s');
        $like = Db::table('up_like_user')
            ->where('like_user_id',$user_id)
            ->where('like_other_id',$uid)
            ->find();
        if($like){
            $res = Db::table('up_like_user')->where('like_id',$like['like_id'])->delete();
        }else{
            $res = Db::table('up_like_user')->insert([
                'like_other_id' => $uid,
                'like_user_id' => $user_id,
                'like_time' => $today
            ]);
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    /**
     * 主页面
     * @return \think\response\Json
     */
    public function getMain()
    {
        extract(input());
        $lunbo = Db::table('up_banner')
            ->where('banner_status',1)
            ->where('banner_type',1)
            ->where('banner_index',2)
            ->order('banner_sort desc')
            ->field('banner_id,banner_where,banner_type,banner_img,banner_title,banner_pp_id,banner_s_id')
            ->select();
        //1、
        $whereForS = [
            's_status' => 1,
            'pp_status' => 1,
            't_status' => 1,
            'p_status' => 1,
        ];
        $pps = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where('s_index',2)
            ->where($whereForS)
            ->order('s_sort desc')
            ->page(1,2)
            ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
            ->select();
        $ppsNum = Db::table('up_store s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where('s_index',2)
            ->where($whereForS)
            ->count();
        $pps22 = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index2',2)
            ->order('s_sort desc')
            ->page(1,2)
            ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
            ->select();
        $ppsNum22 = Db::table('up_store s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index2',2)
            ->count();
        $pps33 = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index3',2)
            ->order('s_sort desc')
            ->page(1,2)
            ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
            ->select();
        $ppsNum33 = Db::table('up_store s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index3',2)
            ->count();
        $pps44 = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index4',2)
            ->order('s_sort desc')
            ->page(1,2)
            ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
            ->select();
        $ppsNum44 = Db::table('up_store s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index4',2)
            ->count();
        $pps55 = Db::table('up_store')->alias('s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index5',2)
            ->order('s_sort desc')
            ->page(1,2)
            ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
            ->select();
        $ppsNum55 = Db::table('up_store s')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->join('up_place p','s.s_p_id=p.p_id','LEFT')
            ->where($whereForS)
            ->where('s_index5',2)
            ->count();
        $cases = Db::table('up_case')
            ->where('case_index',2)
            ->where('case_status',1)
            ->order('case_sort desc')
            ->page(1,2)
            ->field('case_id,case_name,case_thumb,case_two_pic')
            ->select();
        $casesNum = Db::table('up_case')
            ->where('case_index',2)
            ->where('case_status',1)
            ->count();
        $users = Db::table('up_u_user')
            ->where('user_d_type',2)
            ->where('user_status',1)
            ->where('user_d_index',2)
            ->order('user_sort desc')
            ->page(1,2)
            ->field('user_id,user_image,user_d_name')
            ->select();
        $usersNum = Db::table('up_u_user')
            ->where('user_d_type',2)
            ->where('user_status',1)
            ->where('user_d_index',2)
            ->count();
        $goods = Db::table('up_store_goods')
            ->where('good_status',1)
            ->where('good_index',2)
            ->order('good_sort desc')
            ->page(1,2)
            ->field('good_id,good_name,good_thumb')
            ->select();
        $goodsNum = Db::table('up_store_goods')
            ->where('good_status',1)
            ->where('good_index',2)
            ->count();
        if(isset($user_id) && $user_id && $user_id > 0){
            $data = Db::table('up_u_user')
                ->where('user_id',$user_id)
                ->field('user_id,user_cases,user_sps,user_users,user_d_auth_uids,user_d_auth_sids')
                ->find();
            if($data['user_sps']){
                $pps2 = Db::table('up_store')->alias('s')
                    ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
                    ->where('s_id','in',$data['user_sps'])
                    ->where('s_status',1)
                    ->where('pp_status',1)
                    ->order('s_sort desc')
                    ->page(1,2)
                    ->field('pp_id,pp_name,s_id,pp_thumb,s_two_pic,pp_two_pic')
                    ->select();
                if($pps2) {
                    $pps = $pps2;
                    $ppsNum = count(explode(',',$data['user_sps']));
                }
            }
            if(!$data['user_d_auth_sids']) $pps = []; // 特殊情况
            if($data['user_cases']){
                $cases2 = Db::table('up_case')
                    ->where('case_id','in',$data['user_cases'])
                    ->where('case_status',1)
                    ->order('case_sort desc')
                    ->page(1,2)
                    ->field('case_id,case_name,case_thumb,case_two_pic')
                    ->select();
                if($cases2) {
                    $cases = $cases2;
                    $casesNum = count(explode(',',$data['user_cases']));
                }
            }
            if($data['user_users']){
                $users2 = Db::table('up_u_user')
                    ->where('user_d_type',2)
                    ->where('user_status',1)
                    ->where('user_id','in',$data['user_users'])
                    ->order('user_sort desc')
                    ->page(1,2)
                    ->field('user_id,user_d_name,user_image')
                    ->select();
                if($users2) {
                    $users = $users2;
                    $usersNum = count(explode(',',$data['user_users']));
                }
            }
            if(!$data['user_d_auth_uids']) $users = []; // 特殊情况
        }
        $title = [
            'pps_title' => '',
            'pps_title2' => '',
            'pps_title3' => '',
            'pps_title4' => '',
            'pps_title5' => '',
            'cases_title' => '',
            'users_title' => '',
            'goods_title' => '',
        ];
        $ttab = Db::table('up_about')->where('id','in','7,8,9,25,27,28,33,34')->column('content');
        $ttopen = Db::table('up_about')->where('id','in','15,16,17,26,29,30,31,32')->column('content');
        if($pps && $ttopen[0] == 1) {
            foreach ($pps as $k => $v){
                if($v['pp_two_pic']) $pps[$k]['pp_thumb'] = explode(',',$v['pp_two_pic'])[0];
                if($v['s_two_pic']) $pps[$k]['pp_thumb'] = explode(',',$v['s_two_pic'])[0];
            }
            $title['pps_title'] = $ttab[0];
            $title['pps_title_num'] = $ppsNum;
            $title['pps_more1'] = 1;
        }
        if($pps22 && $ttopen[4] == 1) {
            foreach ($pps22 as $k => $v){
                if($v['pp_two_pic']) $pps22[$k]['pp_thumb'] = explode(',',$v['pp_two_pic'])[0];
                if($v['s_two_pic']) $pps22[$k]['pp_thumb'] = explode(',',$v['s_two_pic'])[0];
            }
            $title['pps_title2'] = $ttab[4];
            $title['pps_title_num2'] = $ppsNum22;
            $title['pps_more2'] = 2;
        }
        if($pps33 && $ttopen[5] == 1) {
            foreach ($pps33 as $k => $v){
                if($v['pp_two_pic']) $pps33[$k]['pp_thumb'] = explode(',',$v['pp_two_pic'])[0];
                if($v['s_two_pic']) $pps33[$k]['pp_thumb'] = explode(',',$v['s_two_pic'])[0];
            }
            $title['pps_title3'] = $ttab[5];
            $title['pps_title_num3'] = $ppsNum33;
            $title['pps_more3'] = 3;
        }
        if($pps44 && $ttopen[6] == 1) {
            foreach ($pps44 as $k => $v){
                if($v['pp_two_pic']) $pps44[$k]['pp_thumb'] = explode(',',$v['pp_two_pic'])[0];
                if($v['s_two_pic']) $pps44[$k]['pp_thumb'] = explode(',',$v['s_two_pic'])[0];
            }
            $title['pps_title4'] = $ttab[6];
            $title['pps_title_num4'] = $ppsNum44;
            $title['pps_more4'] = 4;
        }
        if($pps55 && $ttopen[7] == 1) {
            foreach ($pps55 as $k => $v){
                if($v['pp_two_pic']) $pps55[$k]['pp_thumb'] = explode(',',$v['pp_two_pic'])[0];
                if($v['s_two_pic']) $pps55[$k]['pp_thumb'] = explode(',',$v['s_two_pic'])[0];
            }
            $title['pps_title5'] = $ttab[7];
            $title['pps_title_num5'] = $ppsNum55;
            $title['pps_more5'] = 5;
        }
        if($cases && $ttopen[1] == 1) {
            foreach ($cases as $k => $v){
                if($v['case_two_pic']){
                    $cases[$k]['case_thumb'] = explode(',',$v['case_two_pic'])[0];
                }
            }
            $title['cases_title'] = $ttab[1];
            $title['cases_title_num'] = $casesNum;
            $title['cases_more4'] = 1;
        }
        if($users && $ttopen[2] == 1) {
            $title['users_title'] = $ttab[2];
            $title['users_title_num'] = $usersNum;
            $title['users_more5'] = 1;
        }
        if($goods && $ttopen[3] == 1) {
            $title['goods_title'] = $ttab[3];
            $title['goods_title_num'] = $goodsNum;
            $title['goods_more6'] = 1;
        }
        //--------------------------------
        $thumbs = Db::table('up_about')->where('id','in','10,11,12,13,23')->order('remark')->column('content');
        return json([
            'status'=>200,
            'thumbs'=>$thumbs,          //轮播图
            'msg'=>$lunbo,          //轮播图
            'title'=>$title,     //
            'pps'=>$pps,     //
            'pps22'=>$pps22,     //
            'pps33'=>$pps33,     //
            'pps44'=>$pps44,     //
            'pps55'=>$pps55,     //
            'cases'=>$cases,   //优惠图
            'users'=>$users,
            'goods'=>$goods
        ]);
    }
    //--------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------
    /**
     * 生成省市区json数据：makeJson
     * @return string
     */
    public function makeJson()
    {
        $thumbs = Db::table('up_about')->where('id','in','11,12,10,13,23')->order('remark')->column('id');
        dump($thumbs);die;
//        $video = Db::table('up_pp_video')->field('v_id,v_pp_id')->select();
//        foreach ($video as $k => $v){
//            $sid = Db::table('up_store')->where('s_pp_id',$v['v_pp_id'])->value('s_id');
//            if($sid){
//                Db::table('up_pp_video')->where('v_id',$v['v_id'])->setField('v_s_id',$sid);
//            }
//        }
//        die;
//        set_time_limit(0);
//        $area = file_get_contents('static/area.json');
//        $area2 = json_decode($area,true);
//        return json($area2);
        set_time_limit(0);
        $pro = Db::table('up_area')
            ->where('pid',0)
//            ->where('district_id',1001)
            ->field('district_id id,district name')
            ->order('sort')
            ->select();
        foreach($pro as $k=>$v){
            $pro[$k]['parentId'] = 0;
            $city = Db::table('up_area')
                ->where('pid',$v['id'])
                ->where('level',2)
                ->field('district_id id,district name,pid parentId')
                ->select();
//            foreach ($city as $kk=>$vv){
//                $city[$kk]['sub'] = Db::table('up_area')
//                    ->where('pid',$vv['id'])
//                    ->where('level',3)
//                    ->field('district_id id,district name,pid parentId')
//                    ->select();
//            }
            $pro[$k]['sub'] = $city;
        }
        return json($pro);
    }
    public function datahttps()
    {
//        $table='up_pp_banner';
//        $id='pb_id';
//        $field='pb_url';
//        $page=8;
        extract(input());
        $data = Db::table($table)
            ->field("{$id},{$field}")
            ->page($page,1000)
            ->select();
//        dump($data);die;
        foreach ($data as $k => $v){
            if($v[$field]){
                $arr = explode(':',$v[$field]);
                if($arr[0] == 'http'){
                    $arr[0] = 'https';
                    $mewurl = implode($arr,':');
                    Db::table($table)->where("$id",$v[$id])->setField($field,$mewurl);
                }
            }
        }
    }
}